<%@page import="com.training.java.redbox.domain.Movie"%>
<%@page import="com.training.java.redbox.domain.Customer"%>
<%@page import="com.training.java.redbox.domain.Inventory"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%@include file="Header.jsp"%>


<%--  <jsp:include page = "/redbox/inventory">   error --%>

<%
int size = 0;
List<Long> cart = (List<Long>)session.getAttribute("cart");

if (cart != null) {
	size = cart.size();
}
%>
	
<table border="0" width="800">
		<tr>
			<td align="right">
				<a href="/redbox/Login.jsp"><img src="images/login.jpg" width="80" height="25"/></a>
				<a href="/redbox/Signup.jsp"><img src="images/signup2.jpg" width="80" height="25"></a>
				<img src="images/cart.jpg" width="30" height="25" /> (<%=size%>)
				<a href="/redbox/checkout"><img src="images/checkout.jpg" width="80" height="30" /></a>
			</td>
		</tr>
	</table>
	
	
	
	

	<%
		List<Movie> movies = (List<Movie>) request.getAttribute("movies");
	%>
	
	<table border="0">
		<tr>
			<%
				for (Movie movie : movies) {
			%>
			<td><img src="<%=movie.getImageLocation()%>" width="150" height="225"></td>
																			
			<%	}%>
		</tr>
		
		<tr>
		<%
		
			List<Inventory> inventories = (List<Inventory>) request.getAttribute("Inventories");
		int stock;
	
		%>
		<tr>
			<%
				for (Movie movie : movies) {
					
					for (Inventory inventory : inventories) {
						
					     stock = inventory.getCount();
					     if (stock > 0  && (movie.getId() == inventory.getMovieId())){
					%>
						<td><a href="/redbox/addToCart?id=<%=movie.getId()%>">Add to<img
					src="images/cart.jpg" width="30" height="25"></a>
					stock(<%= stock %>) 
					 
			</td>
			
					 						     
					   <%}
					     
					     else if(stock == 0  && (movie.getId() == inventory.getMovieId())){
					    	 %>	 
					    <td> out of stock  </td>
					     <%}%>
					
						<%}	%>
						
					
			
			

			<%	}%>
			
		</tr>
	</table>
	
	<%@include file="Footer.jsp"%>

</body>
</html>